package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.annotation.TingshuLogin;
import com.atguigu.tingshu.common.result.Result;

import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.user.service.UserInfoService;

import com.atguigu.tingshu.vo.user.UserCollectVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    //Request URL: http://localhost:8500/api/user/userInfo/findUserSubscribePage/1/10
    //todo:实现真正的功能(订阅功能)
    @Operation(summary = "模拟登陆弹窗")
    @GetMapping("/findUserSubscribePage/{pn}/{pz}")
    public Result findUserSubscribePage(@PathVariable("pn")Long pn,
                                        @PathVariable("pz")Long pz){

        return Result.build(null, ResultCodeEnum.LOGIN_AUTH);
    }

    //Request URL: http://localhost:8500/api/user/userInfo/collect/6447

    @Operation(summary = "收藏与取消收藏声音")
    @GetMapping("collect/{trackId}")
    @TingshuLogin
    public Result collect(@PathVariable(value = "trackId") Long trackId){
        Boolean flag = userInfoService.collect(trackId);
        return Result.ok(flag);
    }

//    Request URL: http://localhost:8500/api/user/userInfo/isCollect/6447
    @TingshuLogin
    @Operation(summary = "是否收藏声音")
    @GetMapping("isCollect/{trackId}")
    public Result isCollect(@PathVariable(value = "trackId") Long trackId){
        Boolean flag = userInfoService.isCollect(trackId);
        return Result.ok(flag);
    }

//    Request URL: http://localhost:8500/api/user/userInfo/isSubscribe/125

    @TingshuLogin
    @Operation(summary = "用户是否订阅过专辑")
    @GetMapping("/isSubscribe/{albumId}")
    public Result isSubscribe(@PathVariable(value = "albumId")Long albumId){
        Boolean flag = userInfoService.isSubscribe(albumId);
        return Result.ok(flag);
    }
    //Request URL: http://localhost:8500/api/user/userInfo/findUserCollectPage/1/10
    @TingshuLogin
    @Operation(summary = "查询用户收藏过的声音列表分页展示")
    @GetMapping("findUserCollectPage/{pn}/{pz}")
    public Result findUserCollectPage(@PathVariable("pn")Long pn,
                                      @PathVariable("pz")Long pz){

        IPage<UserCollectVo> page = new Page<>(pn,pz);
        page = userInfoService.findUserCollectPage(page);
        return Result.ok(page);
    }


}

